package com.to8to.autotask;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.apache.thrift.TException;

import com.to8to.autotask.rpc.CallClient;
import com.to8to.crm.common.ThriftClientFactory;
import com.to8to.thrift.crm.autotask.AutoTaskService;
import com.to8to.thrift.crm.autotask.AutoTaskService.Iface;
import com.to8to.thrift.crm.itemdb.ItemDBService;
import com.to8to.thrift.crm.itemdb.TItem;

public class CreateTestData
{
    public static void main(String[] args) throws TException
    {
        //        createYuyueData("18616877162", 1228643, 2093);

        /*for (int i = 0; i < 100; i++)
        {
            allocateSHKF();
        }*/

        ExecutorService pool = Executors.newCachedThreadPool();

        //        keepUserOnline();
        //        allocateSHKF();
        //        iface.allocateSHKFWithSingleProject(11119108, "711");
        //        System.out.println(iface.getOnlineUser());
        /*for (int i = 0; i < 50; i++)
        {
            pool.execute(new Runnable()
            {
                @Override
                public void run()
                {
                    try
                    {
                        iface.allocateSHKFWithSingleProject(1360073, "1229604");
                    }
                    catch (TException e)
                    {
                        e.printStackTrace();
                    }
                }
            });
        }*/
        //System.out.println(iface.isCostForfeit(345517, 28821, 2));

        keepUserOnline();

        //        ExecutorService pool = Executors.newCachedThreadPool();
        //        iface.isCostForfeit(274279, 29260, 1103);

        /*for (int i = 0; i < 1000; i++)
        {
            iface.isCostForfeit(345517, 28821, 2);
        }*/
    }

    static void keepUserOnline_atom()
    {
        try
        {
            AutoTaskService.Iface iface = CallClient.getInstance().getAutoTaskService();

            iface.activeOnline(1264);
            iface.activeOnline(1278);
            iface.activeOnline(1550);
            iface.activeOnline(1262);
        }
        catch (TException e)
        {
            e.printStackTrace();
        }
    }

    static void generateFK() throws TException
    {
        int res = CallClient.getInstance().getQueryService().generateSaleFk(1, 1, 1);
        System.out.println(res);
    }

    static void allocateDSGW() throws TException
    {
        CallClient.getInstance().getAutoTaskService().allocateDSGW();
    }

    static void allocateSHKF() throws TException
    {
        CallClient.getInstance().getAutoTaskService().allocateSHKF();
    }

    static void createYuyueData(String phone, int phoneId, int cityid) throws TException
    {
        ItemDBService.Iface iface = (ItemDBService.Iface) ThriftClientFactory.getClient(ItemDBService.class);
        TItem item = new TItem();
        item.setAddress("LS_Test_Address");

        item.setPhone(phone);
        item.setPhoneId(phoneId);
        item.setChenghu("y先生");
        item.setCityid(cityid);
        item.setUptime((int) (System.currentTimeMillis() / 1000));
        item.setIspass(0);
        int i = iface.insertItem(item);
        System.out.println("Insert Item : " + i);
    }

    static void keepUserOnline() throws TException
    {
        AutoTaskService.Iface iface =
            (Iface) com.to8to.kitt.client.ThriftClientFactory.getClient(AutoTaskService.class, "192.168.1.96", 30000, 10000, null);

        while (true)
        {
            int[] arr = new int[] { 109 };

            for (int i : arr)
                iface.activeOnline(i);

            System.out.println(iface.getOnlineUser());
            try
            {
                TimeUnit.SECONDS.sleep(10);
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    }
}
